#ifndef WL_EXT_RECORDER_PCM_H
#define WL_EXT_RECORDER_PCM_H

/**
 * 录音的实现流程
 * 开始录音，然后通过回调函数，通过WL_EXT_RECORD_DATA回调给上层，上层可以通过wl_ext_record_get_data获取数据
 * 然后可以通过wl_ext_record_stop停止录音
 */

/**
 * recorder handle
 */
typedef void* wl_ext_recorder_handle;

/**
 * recorder event
 */
enum {
    WL_EXT_RECORD_STARTED = 0, // recorder has been started
    WL_EXT_RECORD_STOPPED, // recorder has been stopped
    WL_EXT_RECORD_ERROR, // recorder error
    WL_EXT_RECORD_DATA // recorder sample data ready, it should defined by init parameter "sampleFramesEach"
};

/**
 * recorder callback
 * 
 * @param handle recorder handle
 * @param event recorder event
 * @param pContext recorder context
 */
typedef void (*wl_ext_record_callback)(wl_ext_recorder_handle handle, int event, void* pContext);

/**
 * init recorder
 * 
 * @param sampleRate sample rate
 * @return 0 success, < 0 fail
 */
int wl_ext_record_init(int sampleRate);

/**
 * deinit recorder
 * 
 * @return 0 success, < 0 fail  
 */
int wl_ext_record_deinit(void);

/**
 * start recorder
 * 
 * @param pHandle recorder handle, when success, it will return recorder handle, else it will return NULL
 * @param callback recorder callback
 * @param pContext recorder context
 * @return 0 success, < 0 fail
 * 
 */
wl_ext_recorder_handle wl_ext_record_start(wl_ext_record_callback callback, void* pContext);

/**
 * stop recorder
 * 
 * @param handle recorder handle
 * @return 0 success, < 0 fail  
 */
int wl_ext_record_stop(wl_ext_recorder_handle handle);

/**
 * get recorder data
 * 
 * @param handle recorder handle
 * @param pPcmData pcm data in byte format  
 * @param pcmLen  bytes of pcm data
 * @return > 0 means bytes actually read, < 0 means error 
 */
int wl_ext_record_get_data(wl_ext_recorder_handle handle, unsigned char *pPcmData, unsigned int pcmLen);

#endif
